﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace QuanLyDuocPham.Controllers.UC.QuanLyHeThong.DanhMuc
{
    /// <summary>
    /// Interaction logic for UC_HOATCHAT_List.xaml
    /// </summary>
    public partial class UC_HOATCHAT_List : UserControl, IDisposable
    {
        public void Dispose()
        {
            if (hoatchatctrl != null)
            {
                hoatchatctrl.Dispose();
                hoatchatctrl = null;
            }
        }
        public UC_HOATCHAT_List()
        {
            InitializeComponent();
        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            loadHOATCHAT();
        }
        Controllers.QuanLyHeThong.DanhMuc.HOATCHAT_Control hoatchatctrl = new Controllers.QuanLyHeThong.DanhMuc.HOATCHAT_Control();
        private void loadHOATCHAT()
        {
            
            hoatchatctrl.loadData(dataPager1);
            
        }

        private void btnAddHOATCHAT_Click(object sender, RoutedEventArgs e)
        {
            View.QuanLyHeThong.DanhMuc.HOATCHAT_Add_View addhoatchat = new View.QuanLyHeThong.DanhMuc.HOATCHAT_Add_View();
            addhoatchat.done = new View.QuanLyHeThong.DanhMuc.HOATCHAT_Add_View.added(loadHOATCHAT);
            addhoatchat.ShowDialog();
        }

        private void btnEditHOATCHAT_Click(object sender, RoutedEventArgs e)
        {
            if (lvHOATCHAT_List.SelectedItem == null)
            {
                MessageBox.Show("Vui lòng chọn hoạt chất cần sửa!");
            }
            else
            {
                View.QuanLyHeThong.DanhMuc.HOATCHAT_Edit_View edithoatchat = new View.QuanLyHeThong.DanhMuc.HOATCHAT_Edit_View();
                edithoatchat._ma_hoatchat = lvHOATCHAT_List.SelectedValue.ToString();
                edithoatchat.done = new View.QuanLyHeThong.DanhMuc.HOATCHAT_Edit_View.added(loadHOATCHAT);
                edithoatchat.ShowDialog();
            }
        }
        
        private void btnDeleteHOATCHAT_Click(object sender, RoutedEventArgs e)
        {
            if (lvHOATCHAT_List.SelectedItem == null)
            {
                MessageBox.Show("Vui lòng chọn hoạt chất cần xóa!");
            }
            else
            {

                if (MessageBox.Show("Bạn có chắc chắn muốn xóa hoạt chất này?", "Cảnh báo", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                {
                    string error = "";
                    error = hoatchatctrl.deleteData(lvHOATCHAT_List.SelectedValue.ToString(), error);
                    MessageBox.Show(error);
                }
            }
            loadHOATCHAT();

        }

    }

    

}
